const BaseModel = require("../libs/baseModel.js");
const model = new BaseModel();
const dayjs = require("dayjs");
dayjs.locale("zh-cn");

// 用户表
const _Schema = new model.Schema({
  username: {
    type: String,
    require: true,
  },
  password: {
    type: String,
    require: true,
  },
  status: {
    // 是否禁用
    type: Boolean,
    default: true,
  },
  created: {
    type: String,
  },
},{versionKey:false});

_Schema.post("validate", (doc) => {
  if (!doc.created) {
    const now = dayjs().format("YYYY-MM-DD HH:mm:ss  ");
    doc.created = now;
  }
});

_Schema.post("update", (doc) => {
  const now = dayjs().format("YYYY-MM-DD HH:mm:ss  ");
  this._update["$set"].updated = now;
});

module.exports = model.mongoose.model("users", _Schema);
